package com.etheart.music.web.action.info;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.etheart.model.entity.Album;
import com.etheart.model.entity.Singer;
import com.etheart.model.entity.Song;
import com.etheart.music.service.SongService;
import com.opensymphony.xwork2.ActionSupport;

@Controller("songAction")
@Scope("prototype")  
@ParentPackage("json-default")
public class SongAction extends ActionSupport implements RequestAware{
	    
	private static final long serialVersionUID = 1L;
	@Autowired           
	SongService songService;
	private Long songid;  
	private Song song;
	
	@Action(value="jsong",results={@Result(type="json",name="jsong",params={"excludeNullProperties","true","excludeProperties","song.singer.*s,song.album.*s"})})  
	public String jsong()  { 
		song = songService.findById(songid);
		return "jsong";    
	}
	@Action(value="song",results={@Result(name="success", location="/info/song.jsp")})  
	public String execute()  {   
		jsong();
		Singer singer = song.getSinger();
		Album album = song.getAlbum();
		if (song.getLrcContent()!=null) {
			request.put("lrcContent", songService.parseLrcContent(song));
		}
		request.put("song", song);  
		request.put("singer", singer);  
		request.put("album", album);
		return "success";    
	}
	
	@Action(value="play",results={@Result(name="success", location="/../resource/component/dewplayer/mp3/test3.mp3",type="redirect")})  
	public String play()  {   
		return "success";    
	}

	
	
	public Song getSong() {
		return song;
	}

	public void setSong(Song song) {
		this.song = song;
	}

	Map<String, Object> request;
	public void setRequest(Map<String, Object> arg0) {
		this.request = arg0;
	}
	public Long getSongid() {
		return songid;
	}
	public void setSongid(Long songid) {
		this.songid = songid;
	}
}
 